<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>商品管理 - 编辑今日特卖</title>
<link href="/style/css/summernote.css" rel="stylesheet">

<?php include $this->c['_homes']['_viewsHome'] . '/_global/_head.php';?>

</head>
<!-- BEGIN BODY -->
<body class="page-header-fixed page-sidebar-fixed">

<!-- BEGIN HEADER -->
<?php include $this->c['_homes']['_viewsHome'] . '/_global/head.php';?>
<!-- END HEADER -->
<div class="clearfix"></div>
<!-- BEGIN CONTAINER -->
<div class="page-container" >
  <!-- BEGIN HORIZONTAL MENU PAGE SIDEBAR1 -->
  <?php include $this->c['_homes']['_viewsHome'] . '/_global/menu.php';?>
  <!-- END BEGIN HORIZONTAL MENU PAGE SIDEBAR -->
  <!-- BEGIN PAGE -->
  <div class="page-content">
    <!-- BEGIN PAGE HEADER-->
    <div class="row">
      <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title"> 编辑今日特卖 </h3>
        <ul class="page-breadcrumb breadcrumb">
          <li> <i class="icon-home"></i> <a href="/manage">后台</a> <i class="icon-angle-right"></i> </li>
          <li> 广告管理 <i class="icon-angle-right"></i> </li>
          <li> <a href="today_special">今日特卖列表</a> <i class="icon-angle-right"></i> </li>
          <li>编辑今日特卖</li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
      </div>
    </div>
    <!-- END PAGE HEADER-->
    <!-- BEGIN PAGE CONTENT-->

    <div class="row">
      <div class="col-md-12">
        <!-- BEGIN SAMPLE FORM PORTLET-->
        <form class="form-horizontal" method="post" action="/channel/savespecial" id="add" onSubmit="return chkfrm();" role="form" enctype="multipart/form-data">
            <input type="hidden" name="act" value="edit">
            <input type="hidden" name="id" value="<?=$this->data['id']?>">
            <input type="hidden" name="ids" value="<?=$this->data['goods_ids']?>">
          <div class="tabbable tabbable-custom boxless">
            <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_0" data-toggle="tab">今日特卖信息</a></li>
            </ul>
            <div class="tab-content">
              <!--Tab0-->
              <div class="tab-pane active" id="tab_0">
                <div class="portlet box blue ">
                  <div class="portlet-title">
                    <div class="caption"> <i class="icon-reorder"></i> 今日特卖信息 </div>
                  </div>
                  <div class="portlet-body form">
                    <div class="form-body">
                        <div class="form-group withdraw withdraw-bank">
                            <label  class="col-md-2 control-label"  for="num_id"><span class="required">*</span> 起止日期</label>
                            <div class="col-md-4" id="data_5">
                                <div class="input-group">
                                    <input type="text" id="start_time" class="input-sm form-control"  autocomplete="off" name="start_time" placeholder="开始时间" value="<?=date("Y-m-d H:i:s",$this->data['start_time'])?>">
                                    <span class="input-group-addon">到</span>
                                    <input type="text" id="end_time" class="input-sm form-control"  autocomplete="off" name="end_time" placeholder="结束时间" value="<?=date("Y-m-d H:i:s",$this->data['end_time'])?>">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-md-2 control-label"  for="num_id"><span class="required"></span>商品搜索</label>
                            <div class="col-md-7">
                                <div class="input-group">
                                    <input type="text" id="goods_search" class="input-sm form-control"  autocomplete="off" name="goods_search" placeholder="输入商品名称" value="">
                                </div>
                            </div>
                        </div>

                      <div class="form-group" id="goods_list" style="display: none;">
                        <label  class="col-md-2 control-label">商品信息</label>
                        <div class="col-md-6">
                          <select id="goods-ids" class="form-control">

                          </select>
                        </div>
                      </div>

                        <div class="index_block goods-list">
                            <h2 class="far_right">商品预览：</h2>
                            <div nctype="item_content" class="mb-item-edit-content content">
                                <table class="table table-striped table-bordered table-hover dataTable">
                                    <thead class="add_top">
                                    <tr>
                                        <td>商品id</td>
                                        <td>商品名称</td>
                                        <td>商品价格</td>
                                        <td>操作</td>
                                    </tr>
                                    </thead>
                                    <tbody class="add_main" id="add_goods">
                                    <?php
                                        if($this->data['goods']){
                                          foreach($this->data['goods'] as $v){

                                     ?>
                                      <tr class="tr-goods" data-id="<?=$v['goods_id']?>">
                                          <td><?=$v['goods_id']?></td>
                                          <td><?=$v['goods_name']?></td>
                                          <td><?=$v['shop_price']?></td>
                                          <td><a nctype="btn_del_item_image" href="javascript:;" onclick="del_goods(this)">删除</a></td>
                                    </tr>
                                    <?php }}?>
                                    </tbody>
                                </table>
                            </div>
                        </div>

                    </div>
                    <div class="form-actions fluid">
                      <div class="col-md-offset-3 col-md-9">
                        <button type="submit" class="btn green" id="ss">提交</button>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </form>
        <!-- END SAMPLE FORM PORTLET-->
      </div>
    </div>
    <!-- END PAGE CONTENT-->
  </div>
  <!-- END PAGE -->
</div>
<!-- END CONTAINER -->
<?php include $this->c['_homes']['_viewsHome'] . '/_global/_footer.php';?>
<!-- <script type="text/javascript" src="/style/assets/plugins/ckeditor/ckeditor.js"></script> -->
<script src="/style/js/layer/layer.min.js" type="text/javascript"></script>
<script src="/style/js/layer/laydate.js" type="text/javascript"></script>
<script>
jQuery(document).ready(function() {    
   App.init();

    laydate.render({
        elem: '#start_time'
        ,type: 'datetime',

    });

    laydate.render({
        elem: '#end_time'
        ,type: 'datetime'

    });
});

$('#goods_search').on('input propertychange',function(){

        $.post('/channel/ajax', {act:'goods_search',keyword: $(this).val()}, function (res) {
            if (res !=null && res !='') {
                  var html  ='<option value="">商品信息</option>';

                $.each(res,function(i, v){
                    html +='<option value="'+v.goods_id+'">['+v.goods_id+']'+v.goods_name+' - '+v.shop_price+'</option>';
                })

                $("#goods_list").show();
                $('#goods-ids').html(html);

            }else{

                $("#goods_list").hide();
            }
        },'json');

});

function del_goods(obj) {
    $(obj).parent().parent().remove();
}

$("#goods-ids").change(function(){
    var goods_id = $(this).val();

    if(goods_id !='' ){
        var done = true;
        $(".tr-goods").each(function(index,obj){
              if(goods_id == $(this).attr('data-id')){

                  done =false;
              }

        })

        if(done){
            $.post('/channel/ajax', {act:'goods_detail',goods_id: $(this).val()}, function (res) {
                if (res !=null && res !='') {
                    var html  ='<tr class="tr-goods" data-id="'+res.goods_id+'"><input type="hidden" name="goods_id" value="'+res.goods_id+'"><td>'+res.goods_id+'</td><td>'+res.goods_name+'</td><td>'+res.shop_price+'</td><td><a nctype="btn_del_item_image" href="javascript:;" onclick="del_goods(this)">删除</a></td></tr>';
                    $('#add_goods').append(html);

                }
            },'json');


        }



    }


    /*




   */


})

function chkfrm(){

    if($("#start_time").prop("value")==""){
        swal("请选择开始时间");
        return false;
    }

    if($("#end_time").val()==""){
        swal("请选择结束时间");
        return false;
    }
   var ids = "";
    $(".tr-goods").each(function(index,obj){
        if($(this).attr('data-id')){
            if(ids ==""){

                ids = $(this).attr('data-id');
            }else{
                ids +=","+$(this).attr('data-id');

            }

        }

    })

    if(ids ==""){

        swal("请添加商品信息");

        return false;

    }

    $("input[ name='ids']").val(ids);




}


</script>
<script type="text/javascript">

    /**
     * 使用HTML5的FormData上传图片
     */
/*      function fileupload()
    {
 	   
         var data = document.getElementById('head_image');
         var fd =new FormData();
         fd.append('pic', data.files[0]);
    	
         $.ajax({
              url: "/adv/upload_img",
              type: "POST",
              data: fd,
              processData: false,  // 告诉jQuery不要去处理发送的数据
              contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
              success: function(response,status,xhr){
            	  var response=eval("("+response+")");
            	
                 //$('#showimage_'+id).attr('src', response.path);
                 $('#_pic').val(response.pic_id);
                 $("#imgs").show();
                 $('#imgs').find('a').attr('href',response.path)
              }
         });
         return false;
    } */
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>